package com.unience.ec2.eclipse.dialog;

import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class NewSecurityGroupDialog extends org.eclipse.swt.widgets.Dialog {

	private Shell dialogShell;
	private Label Name;
	private Button buttonCancel;
	private Composite composite1;
	private Button buttonAccept;
	private Canvas canvas1;
	private Text text;
	private Label labelDesc;
	private Text textName;
	
	
	private boolean accepted = false;
	private String name;
	private String desc;

	/**
	* Auto-generated main method to display this 
	* org.eclipse.swt.widgets.Dialog inside a new Shell.
	*/
	public static void main(String[] args) {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			NewSecurityGroupDialog inst = new NewSecurityGroupDialog(shell, SWT.NULL);
			inst.open();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public NewSecurityGroupDialog(Shell parent, int style) {
		super(parent, style);
	}

	public void open() {
		try {
			Shell parent = getParent();
			dialogShell = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

			this.setText("Create New Security Group");
			GridLayout dialogShellLayout = new GridLayout();
			dialogShellLayout.numColumns = 2;
			dialogShell.setLayout(dialogShellLayout);
			dialogShell.layout();
			dialogShell.pack();			
			dialogShell.setSize(343, 133);
			{
				Name = new Label(dialogShell, SWT.NONE);
				Name.setText("Name");
				GridData NameLData = new GridData();
				Name.setLayoutData(NameLData);
			}
			{
				textName = new Text(dialogShell, SWT.NONE);
				GridData textNameLData = new GridData();
				textNameLData.widthHint = 245;
				textNameLData.heightHint = 17;
				textName.setLayoutData(textNameLData);
			}
			{
				labelDesc = new Label(dialogShell, SWT.NONE);
				labelDesc.setText("Description");
				GridData labelDescLData = new GridData();
				labelDesc.setLayoutData(labelDescLData);
			}
			{
				text = new Text(dialogShell, SWT.NONE);
				GridData textLData = new GridData();
				textLData.widthHint = 244;
				textLData.heightHint = 17;
				text.setLayoutData(textLData);
			}
			{
				GridData canvas1LData = new GridData();
				canvas1LData.widthHint = 64;
				canvas1LData.heightHint = 19;
				canvas1 = new Canvas(dialogShell, SWT.NONE);
				canvas1.setLayoutData(canvas1LData);
			}
			{
				GridData composite1LData = new GridData();
				composite1LData.widthHint = 127;
				composite1LData.heightHint = 44;
				composite1LData.horizontalAlignment = GridData.END;
				composite1 = new Composite(dialogShell, SWT.NONE);
				GridLayout composite1Layout = new GridLayout();
				composite1Layout.makeColumnsEqualWidth = true;
				composite1Layout.numColumns = 2;
				composite1.setLayout(composite1Layout);
				composite1.setLayoutData(composite1LData);
				{
					buttonAccept = new Button(composite1, SWT.PUSH | SWT.CENTER);
					buttonAccept.setText("Accept");
					buttonAccept.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							System.out.println("buttonAccept.widgetSelected, event="+evt);
							accepted = true;
							name = textName.getText();
							desc = text.getText();
							
							dialogShell.close();
							
							
						}
					});
				}
				{
					buttonCancel = new Button(composite1, SWT.PUSH | SWT.CENTER);
					buttonCancel.setText("Cancel");
					buttonCancel.addSelectionListener(new SelectionAdapter() {
						public void widgetSelected(SelectionEvent evt) {
							System.out.println("buttonCancel.widgetSelected, event="+evt);
							dialogShell.close();
						}
					});
				}
			}
			dialogShell.setLocation(getParent().toDisplay(100, 100));
			dialogShell.open();
			Display display = dialogShell.getDisplay();
			while (!dialogShell.isDisposed()) {
				if (!display.readAndDispatch())
					display.sleep();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean isAccepted() {
		return accepted;
	}

	public void setAccepted(boolean accepted) {
		this.accepted = accepted;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}
	
}
